/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAL;
import DTO.*;
import UTIL.*;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
 *
 * @author Huong Giang
 */
public class ThanhToanDAL {
    public static boolean insertTT(Thanhtoan emp) throws Exception {
         boolean result = true;
        try {
            Connection connect = SqlDataAccessHelper.getConnection();
            CallableStatement cs = connect.prepareCall("{call sp_InsertTT(?, ?, ?,?)}");
            cs.setInt("CMT", emp.getCmt());
            cs.setInt("Maphong", emp.getMaPhong());
            cs.setDate("NgayTT", emp.getNgayTT());
            cs.setInt("SoTien", emp.getSoTien());
            int n = cs.executeUpdate();
            if (n == 0) {
                result =false;
            }
            
            connect.close();
        } catch (SQLException ex) {
        }        
        return result;

    }
    
    public static boolean updateTT(Thanhtoan emp) {
        boolean result = true;
        try {
            Connection connect = SqlDataAccessHelper.getConnection();
            CallableStatement cs = connect.prepareCall("{call sp_UpdateTT( ?,?,?,?)}");
            cs.setInt("Maphong", emp.getMaPhong());
            cs.setDate("NgayThue", emp.getNgayTT());
            cs.setInt("SoTien", emp.getSoTien());
            int n = cs.executeUpdate();
            if (n == 0) {
                result = false;
            }
            connect.close();
        } catch (SQLException ex) {
        }
        return result;       
    }
    public static boolean checkTTByCMT(int CMT) {
        boolean result = false;
        try {
            Connection connect = SqlDataAccessHelper.getConnection();
            CallableStatement cs = connect.prepareCall("{call sp_selectTT(?)}");
            cs.setInt("CMT", CMT);
            ResultSet rs = cs.executeQuery();
            if (rs.next()) {
                result = true;
            }
            connect.close();
        } catch (SQLException ex) {
        }
        return result;
    }
}